home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume3 / perlshar < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  2.1 KB

  1. Path: xanth!mcnc!ncsuvx!lll-winken!lll-tis!ames!necntc!ncoast!allbery
  2. From: gz@spt.entity.com (Gail Zacharias)
  3. Newsgroups: comp.sources.misc
  4. Subject: v03i040: a perl shar file maker
  5. Message-ID: <310@spt.entity.com>
  6. Date: 27 May 88 23:14:22 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: gz@spt.entity.com (Gail Zacharias)
  9. Organization: The Entity, Cambridge, MA
  10. Lines: 58
  11. Approved: allbery@ncoast.UUCP
  12.  
  13. comp.sources.misc: Volume 3, Issue 40
  14. Submitted-By: "Gail Zacharias" <gz@spt.entity.com>
  15. Archive-Name: perlshar
  16.  
  17. This is a little perl script to create shar files.  Usage is as in:
  18.     perl shar.p input files > sharfile
  19.  
  20. #! /bin/sh
  21. # This is a shell archive, meaning:
  22. # 1. Remove everything above the #! /bin/sh line.
  23. # 2. Save the resulting text in a file.
  24. # 3. Execute the file with /bin/sh (not csh) to create the files:
  25. #    shar.p
  26. #
  27. if test -f 'shar.p'
  28. then
  29.     echo shar: will not over-write existing file "'shar.p'"
  30. else
  31.     echo x - 'shar.p'
  32.     sed 's/^X//' >'shar.p' << 'SHAR_EOF'
  33. Xprint "#! /bin/sh
  34. X# This is a shell archive, meaning:
  35. X# 1. Remove everything above the #! /bin/sh line.
  36. X# 2. Save the resulting text in a file.
  37. X# 3. Execute the file with /bin/sh (not csh) to create the files:
  38. X#    ",join("\n#\t",@ARGV),"\n#\n";
  39. X
  40. Xwhile ($arg = shift) {
  41. X  @dirs = split(/\//,$arg);
  42. X  for ($i=0; $i < $#dirs; $i++) {
  43. X    $dir .= $dirs[$i];
  44. X    if ($dir && !$done{$dir}) {
  45. X      print "if test ! -d '$dir'\nthen\n\tmkdir '$dir'\nfi\n";
  46. X      $done{$dir} = 1;
  47. X    }
  48. X    $dir .= "/";
  49. X  }
  50. X  @stat = stat($arg);
  51. X  $size = $stat[7];
  52. X  open(file, $arg);
  53. X  print "if test -f '$arg'\nthen\n";
  54. X  print "\techo shar: will not over-write existing file \"'$arg'\"\n";
  55. X  print "else\n";
  56. X  print "\techo x - '$arg'\n";
  57. X  print "\tsed 's/^X//' >'$arg' << 'SHAR_EOF'\n";
  58. X  while (<file>) { print "X",$_; }
  59. X  print "SHAR_EOF\n";
  60. X  print "if test $size -ne \"`wc -c < '$arg'`\"\nthen\n";
  61. X  print "\techo shar: error transmitting \"'$arg'\" '(should have been $size characters)'\nfi\nfi\n";
  62. X}
  63. Xprint "echo Done\nexit 0\n";
  64. SHAR_EOF
  65. if test 1014 -ne "`wc -c < 'shar.p'`"
  66. then
  67.     echo shar: error transmitting "'shar.p'" '(should have been 1014 characters)'
  68. fi
  69. fi
  70. echo Done
  71. exit 0
  72.